package com.cskaoyan.controller.backStage;

import com.cskaoyan.model.SearchHistory;
import com.cskaoyan.model.bo.BaseParamBO;
import com.cskaoyan.model.vo.BaseRespVO;
import com.cskaoyan.model.vo.DataVO;
import com.cskaoyan.service.SearchHistoryService;
import com.cskaoyan.util.StringUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：huzhouming
 * @description：用户管理 搜索历史
 * @date ：2022/5/6 14:25
 */
@RestController
@RequestMapping("admin/history")
public class SearchHistoryController {
    @Autowired
    SearchHistoryService searchHistoryService;
    @RequiresPermissions("admin:history:list")
    @GetMapping("list")
    /**
     * @author: huzhouming
     * @description: 查询历史数据
     * @date: 2022/5/6
     * @param paramBO
     * @param userId
     * @param keyword
     * @return com.cskaoyan.model.vo.BaseRespVO
     */
    public BaseRespVO list(BaseParamBO paramBO, String userId, String keyword) {
        DataVO<SearchHistory> dataVO;
        try {
            Integer i;
            if (StringUtil.isEmpty(userId)) {
                i = null;
            } else {
                i = Integer.parseInt(userId);
            }
            dataVO = searchHistoryService.query(paramBO, i, keyword);
        } catch (
                Exception e) {
            return BaseRespVO.parameterError("参数值不对");
        }
        return BaseRespVO.ok(dataVO);
    }
}
